import urllib3
import json
http = urllib3.PoolManager()  # 线程池生成请求
res = http.request('GET', 'https://api.bemfa.com/api/device/v1/bin?uid=35a097fd48214dae19d955c618c467d4&topic=runyun006&type=1')

'''
5723001	缺少uid字段
5723002	uid值为空或不正确
5723003	缺少type字段
5723004	type值为空或不正确
5723005	缺少topic字段
5723007	获取成功
5724009	固件为空不存在
'''
#{"code":5723007,"data":{"url":"http:\/\/bin.bemfa.com\/b\/.bin","time":"2023-07-11 21:13:46","v":"19","tag":""}}
jsonobject = json.loads(res.data.decode())
successed=False
match jsonobject["code"]:
    case 5723001:print('缺少uid字段')
    case 5723002:print('缺少uid字段')
    case 5723003:print('缺少type字段')
    case 5723004:print('type值为空或不正确')
    case 5723005:print('缺少topic字段')
    case 5723007:
        print('获取成功')
        successed=True
    case 5724009:print('固件为空不存在')

print('当前版本发布号:'+(str(int(jsonobject['data']['v'])+1) if successed else '1'))
with open("./src/ota_version.h",mode='w',encoding='utf-8') as ff:
            ff.write( '#define OTA_VER '+str(int(jsonobject['data']['v'])+1) if successed else '#define OTA_VER '+'1')